# ifndef __MIWIDGY__H_

# define __MIWIDGY__H_

#include <iostream>

using namespace std;

# include "../Vista/vista.h"

# include "../Modelo/lienzo.h"  

# include "../Modelo/modelo.h"  

# include "../Modelo/figura.h"  

# include "qtpaint.h"

# include "about.h"

# include <cmath>

# include <fstream>

# include <stdlib.h>

# include <qapplication.h>

# include <qwidget.h>

# include <qpainter.h>

# include <qvariant.h>

# include <qmainwindow.h>

# include <qvariant.h>

# include <qpushbutton.h>

# include <qgroupbox.h>

# include <qframe.h>

# include <qlayout.h>

# include <qtooltip.h>

# include <qwhatsthis.h>

# include <qaction.h>

# include <qmenubar.h>

# include <qpopupmenu.h>

# include <qtoolbar.h>

# include <qimage.h>

# include <qpixmap.h>

# include <qfiledialog.h>

# include <qslider.h>

class WidgetLienzoQT: public QWidget, public Vista
{
	Q_OBJECT
	
	public:
	
		WidgetLienzoQT (QWidget* parent= 0 , const char* name = 0, Modelo* m = NULL):QWidget(parent, name, WStaticContents ), Vista(m)
		{
			temp = NULL;
			
			finPoligono = false;
			
			accion = seleccionar;
			
			pintaAccion.clear();
			
			portaPapeles.clear();
			
			seleccionadas.clear();
			
			nombre = "guardado.paint";
		};
	
		~WidgetLienzoQT()
		{
			seleccionadas.clear();
			
			portaPapeles.clear();
		};

		void actualizar();

		void setSliders(QSlider* r, QSlider* g, QSlider* b, QButton* c)
		{
			sliderR = r;
			
			sliderG = g;
			
			sliderB = b;
			
			aplicarColor = c;
		}
		
	public slots:
	
		virtual void agrupaEvento ();
		
		virtual void desagrupaEvento ();
		
		virtual void borraEvento ();
		
		virtual void copiaEvento ();
		
		virtual void cortaEvento ();
		
		virtual void pegaEvento ();
		
		virtual void setAccionP () 		
		{ 
			accion = punto;		
			
			setAccion();
		};
		
		virtual void setAccionR () 		
		{ 
			accion = rectangulo;	
			
			setAccion();
		};
		
		virtual void setAccionPol () 	
		{ 
			accion = poligono; 	
			
			setAccion();
		};
		
		virtual void setAccionL () 		
		{ 
			accion = linea; 		
			
			setAccion();
		};
		
		virtual void setAccionS () 		
		{ 
			accion = seleccionar;	
			
			setAccion();
		};
		
		virtual void setAccionC () 		
		{ 
			accion = circulo;		
			
			setAccion();
		};
		 
		virtual void Nuevo () 
		{
			lienzo->Iniciar(); 
			
			actualizar();
		};
		
		virtual void Guardar ();
		
		virtual void GuardarComo ();
		
		virtual void Abrir();
		
		virtual void cambiaColor(); 
		
		virtual void cambioR(int val);
		
		virtual void cambioG(int val);
		
		virtual void cambioB(int val);
		 
		virtual void Deshacer() 
		{
			lienzo->Deshacer(); 
			
			seleccionadas.clear(); 
			
			actualizar();
		};
		
		virtual void Rehacer() 
		{
			lienzo->Rehacer();
			
			actualizar();
		};
		
	protected:
		
		void paintEvent( QPaintEvent *);
		
		void mousePressEvent( QMouseEvent *e);
		
		void mouseReleaseEvent( QMouseEvent *e);
		
		void mouseMoveEvent( QMouseEvent *);
    
	private:
		
		QPoint anterior;
		
		QPoint primero;

		void pintaFigura(Figura*, QColor, bool = false, bool = false);
		
		bool pinchaDentro(QMouseEvent*);
		
		QSlider* sliderR;
		
		QSlider* sliderG;
		
		QSlider* sliderB;
		
		QButton* aplicarColor;
		
		int r, g, b;
};

class MyPaint: public QtPaint
{
	Q_OBJECT
	
	public:
	
		MyPaint();
		
		~MyPaint();
	
	public slots:
		
		void quit() 
		{
			qApp->quit();
		};
		
		virtual void Sobre() 
		{
			about->show();
		} 
		
	protected:
	
		WidgetLienzoQT* wli;
		
		About* about;
};

# endif
